package com.ogawa.chair7808.widget;

import android.content.Context;
import androidx.viewpager.widget.ViewPager;
import android.util.AttributeSet;
import android.view.MotionEvent;


/**
 * 自定义(控制可滑动，不可滑动)
 * @author fhb
 *
 */
public class CustomViewPager extends ViewPager {
	
	private setOnViewPagerScrollAction mAction;

	public CustomViewPager(Context context, AttributeSet attrs) {
		super(context, attrs);

	}

	@Override
	public boolean onInterceptTouchEvent(MotionEvent event) {
		if(mAction != null && mAction.unAbleScroll()){
			return false;
		}
		return super.onInterceptTouchEvent(event);
	}
	//去除页面切换时的滑动翻页效果
	@Override
	public void setCurrentItem(int item, boolean smoothScroll) {
		// TODO Auto-generated method stub
		super.setCurrentItem(item, smoothScroll);
	}
	//去除页面切换时的滑动翻页效果
	@Override
	public void setCurrentItem(int item) {
		// TODO Auto-generated method stub
		super.setCurrentItem(item, false);
	}

	@Override
	public boolean onTouchEvent(MotionEvent event) {
		if(mAction != null && mAction.unAbleScroll()){
			return false;
		}
		return super.onTouchEvent(event);
	}
	
	public void setOnViewPagerScrollAction(setOnViewPagerScrollAction action) {
		this.mAction = action;
	}
	
	public interface setOnViewPagerScrollAction{
		boolean unAbleScroll();
	}



}
